<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 1000px;
            height: 500px;
        }
    </style>
</head>

<body>
    <div>
        <button>开关灯</button>
    </div>
</body>

</html>
<script>
    var but = document.querySelector("button")
    var div = document.querySelector("div")
    var a = 0;
    but.onclick = function () {
        if (a == 0) {
            div.style.backgroundColor = 'black'
            a = 1
        } else {
            div.style.backgroundColor = 'white'
            a = 0
        }
    }
</script>